﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Core.Modal;
using Core.Core;
using System.Text;

namespace www.pages.word
{
    public partial class word : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                try {
                    hid_Project.Value = Request["project"] ?? "0";
                    hid_document.Value = Request["doc"] ?? "0";

                    BindDocument();
                    BindTags();
                }
                catch (Exception ex) {

                }                
            }
        }
        /// <summary>
        /// 
        /// </summary>
        private void BindDocument()
        {
            modal_Document document = DocumentUtil.Get(Convert.ToInt32(hid_Project.Value), Convert.ToInt32(hid_document.Value));
            this.txt_doc_name.Value = document?.doc_name;
            this.txt_doc_comment.Value = document?.doc_comment;
            this.editor1.Value = document?.doc_template;
        }

        #region 查询标签
        private string InitTagSql()
        {
            StringBuilder sbQuery = new StringBuilder();
            if (txt_Tag.Value != "") {
                sbQuery.Append($" and tag_name like '{txt_Tag.Value}'");
            }
            return sbQuery.ToString();
        }

        private void BindTags()
        {
            this.list_tags.DataSource = TagUtil.GetListByDoc(Convert.ToInt32(hid_Project.Value), Convert.ToInt32(hid_document.Value), InitTagSql());
            this.list_tags.DataBind();
        }

        protected void btnQueryTag_Click(object sender, EventArgs e)
        {
            BindTags();
        } 
        #endregion

        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="name"></param>
        ///// <param name="comment"></param>
        ///// <param name="content"></param>
        ///// <param name="color"></param>
        ///// <param name="typs"></param>
        ///// <returns></returns>
        //public string showTagsHtml(string id,string name, string comment, string content, string color, string typs) {
        //    return $"<div class=\"external-event tag\" style=\"background-color:{color};color:#fff;\" data-color=\"{color}\" data-tagid=\"{id}\" data-remark=\"{comment}\" data-content=\"{content}\">{name}</div>";
        //}
    }
}